<?php

/**
 * @name: HOTN AnimeList
 * @author: HammerOnTheNail
 * @link: http://code.google.com/p/hotnanimelist/
 */

// Admin oldal címének meghatározása
$title .= " \ ".HOTN_ANIMELIST_ADMIN_MENU_PROJECT_EDIT;
$text = "";

// POST

if ($_POST['action'] == "save")
{
	$values = $HOTN_ANIMELIST_ADMIN_PROJECT->hotn_animelist_admin_project_save("edit",$_POST);
	if ($values === TRUE)
	{
		$ns -> tablerender(HOTN_ANIMELIST_ADMIN_DEFAULT_ERROR_TITLE, HOTN_ANIMELIST_ADMIN_PROJECT_EDIT);
	}
}

if($_POST['action'] == "edit")
{
	// Szerkesztő megjelenítése
		// Project adatok lekérése
		$sql->db_Select("hotn_animelist_project","*","`project_id` = '".$_POST['project_id']."'");
		$values = $sql->db_Fetch();
		$project_folder = $values['project_folder'];
		$projct_id = $values['project_id'];
		
		// Project genre értékek lekérdezés
		$sql->db_Select("hotn_animelist_genre","*","`project_id` = '".$_POST['project_id']."'");
		while($row = $sql->db_Fetch())
		{
			$values['genre'][$row['genre_id']] = 1;
		}
		
		// Munkatársak
		$sql->db_Select("hotn_animelist_team, ".MPREFIX."user", "user_id, user_name", "user_id = team_id");
		while ($row = $sql->db_Fetch())
		{
			$values['project_users_value'][$row['user_id']] = $row['user_name'];
		}
		
		$usertype = array(
			"project_translator",
			"project_karaoke",
			"project_format",
			"project_manga_format",
			"project_video",
			"project_lector",
			"project_timer"
		);
		foreach ($usertype as $usertype)
		{
			$userid = explode("%",$values[$usertype]);
			foreach ($userid as $userid)
			{
				$values[$usertype][$userid] = 1;
			}
		}
		
		// Képek
		if ($values['project_image_reference']<>"") $values['project_image_reference'] = e_PLUGIN."hotn_animelist/Project/".$project_folder."/".$values['project_image_reference'];
		if ($values['project_image_new']<>"") $values['project_image_new'] = e_PLUGIN."hotn_animelist/Project/".$project_folder."/".$values['project_image_new'];
		if ($values['project_image_1']<>"") $values['project_image_1'] = e_PLUGIN."hotn_animelist/Project/".$project_folder."/thumb_".$values['project_image_1'];
		if ($values['project_image_2']<>"") $values['project_image_2'] = e_PLUGIN."hotn_animelist/Project/".$project_folder."/thumb_".$values['project_image_2'];
		if ($values['project_image_3']<>"") $values['project_image_3'] = e_PLUGIN."hotn_animelist/Project/".$project_folder."/thumb_".$values['project_image_3'];
		if ($values['project_image_4']<>"") $values['project_image_4'] = e_PLUGIN."hotn_animelist/Project/".$project_folder."/thumb_".$values['project_image_4'];
		if ($values['project_image_5']<>"") $values['project_image_5'] = e_PLUGIN."hotn_animelist/Project/".$project_folder."/thumb_".$values['project_image_5'];
		if ($values['project_image_6']<>"") $values['project_image_6'] = e_PLUGIN."hotn_animelist/Project/".$project_folder."/thumb_".$values['project_image_6'];
		
		// Alap adatok
		$values['action'] = e_SELF."?project.edit";
		$values['hidden'] = array("action" => "save","project_id"=>$projct_id);
		$values['project_submit'] = HOTN_ANIMELIST_DEFAULT_FORM_EDIT;
		
		// Nem kellő adatok eltüntetése
		$values['project_forum_show'] = FALSE;
		
		include(e_PLUGIN."hotn_animelist/Admin/project/project.php");
		
}
else
{
	// Választó kiírása
		$sql->db_Select("hotn_animelist_project", "project_id, project_name, project_mode, project_type","ORDER BY project_type, project_name ASC","");
		while ($row = $sql->db_Fetch())
		{
			
			if ($row['project_type'] == "anime") $row['project_type'] = HOTN_ANIMELIST_DEFAULT_ANIME;
			if ($row['project_type'] == "manga") $row['project_type'] = HOTN_ANIMELIST_DEFAULT_MANGA;
			
			if ($row['project_mode'] == "finished")
			{
				$project_finished[$row['project_id']] = $row['project_name']." (".$row['project_type'].")";
			}
			if ($row['project_mode'] == "active")
			{
				$project_active[$row['project_id']] = $row['project_name']." (".$row['project_type'].")";
			}
			if ($row['project_mode'] == "dropped")
			{
				$project_dropped[$row['project_id']] = $row['project_name']." (".$row['project_type'].")";
			}
			if ($row['project_mode'] == "passive")
			{
				$project_passive[$row['project_id']] = $row['project_name']." (".$row['project_type'].")";
			}
			if ($row['project_mode'] == "planned")
			{
				$project_planned[$row['project_id']] = $row['project_name']." (".$row['project_type'].")";
			}
		}
		
		$project = array(
			HOTN_ANIMELIST_ANIMETYPE_ACTIVE => $project_active,
			HOTN_ANIMELIST_ANIMETYPE_FINISHED => $project_finished,
			HOTN_ANIMELIST_ANIMETYPE_PLANNED => $project_planned,
			HOTN_ANIMELIST_ANIMETYPE_PASSIVE => $project_passive,
			HOTN_ANIMELIST_ANIMETYPE_DROPPED => $project_dropped
		); 
		
		$data = array(
			"method" => "post",
			"action" => e_SELF."?project.edit",
			"hidden" => array(
						"action" => "edit",
					),
			"data" => array(
						array(
							"type" => "select",
							"name" => "project_id",
							"group" => "true",
							"text" => HOTN_ANIMELIST_ADMIN_PROJECT_PROJECT_NAME,
							"value" => $project
						),
						array(
							"type" => "submit",
							"value" => HOTN_ANIMELIST_DEFAULT_FORM_EDIT
						)
					)
		);
}


// Admin oldal tartalmának megjelenítése
$text .= "<div style='text-align: center;'>".$HOTN_ANIMELIST_FORM->show_form($data)."</div>";
?>